<template>
  <upload-excel :onSuccess="onSuccess"></upload-excel>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { useI18n } from 'vue-i18n'
import UploadExcel from '@/components/UploadExcel/index.vue'
import { userBatchImport } from '@/api/user-manage'
import { generateData } from './utils'

/**
 * 数据解析成功之后的回调
 */
const i18n = useI18n()
const router = useRouter()
const onSuccess = async ({ results }) => {
  const updateData = generateData(results)
  await userBatchImport(updateData)
  ElMessage.success({
    message: results.length + i18n.t('msg.excel.importSuccess'),
    type: 'success'
  })
  router.push('/user/manage')
}
</script>
